package com.example.mobile2021606144ywr0407homework;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private Button btnMainCz;
    private TextView tvMainQ1;
    private RadioGroup gradMainQ1;
    private RadioButton radioMainBtn1a;
    private RadioButton radioMainBtn1b;
    private RadioButton radioMainBtn1c;
    private RadioButton radioMainBtn1d;
    private TextView tvMainQ2;
    private RadioGroup gradMainQ2;
    private RadioButton radioMainBtn2a;
    private RadioButton radioMainBtn2b;
    private RadioButton radioMainBtn2c;
    private RadioButton radioMainBtn2d;
    private TextView tvMainQ3;
    private RadioGroup gradMainQ3;
    private RadioButton radioMainBtn3a;
    private RadioButton radioMainBtn3b;
    private RadioButton radioMainBtn3c;
    private RadioButton radioMainBtn3d;
    private TextView tvMainQ4;
    private RadioGroup gradMainQ4;
    private RadioButton radioMainBtn4a;
    private RadioButton radioMainBtn4b;
    private RadioButton radioMainBtn4c;
    private RadioButton radioMainBtn4d;
    private Button btnMainGet;
    private EditText TxtMainEnd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        gradMainQ1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                radioButton.getText().toString();
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        gradMainQ2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                radioButton.getText().toString();
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        gradMainQ3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                radioButton.getText().toString();
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        gradMainQ4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                radioButton.getText().toString();
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainGet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int question1 = gradMainQ1.getCheckedRadioButtonId();
                int question2 = gradMainQ2.getCheckedRadioButtonId();
                int question3 = gradMainQ3.getCheckedRadioButtonId();
                int question4 = gradMainQ4.getCheckedRadioButtonId();
                if (question1 == R.id.radio_main_btn1a & question2 == R.id.radio_main_btn2b & question3 == R.id.radio_main_btn3b & question4 == R.id.radio_main_btn4c) {
                    TxtMainEnd.setText("得分：100分");
                }else  if (question1==R.id.radio_main_btn1a & question2==R.id.radio_main_btn2c & question3==R.id.radio_main_btn3b ||question2==R.id.radio_main_btn2c&question3==R.id.radio_main_btn3b&question4==R.id.radio_main_btn4a || question1==R.id.radio_main_btn1a&question3==R.id.radio_main_btn3b&question4==R.id.radio_main_btn4a) {
                    TxtMainEnd.setText("得分：75分");
                }else if(question1==R.id.radio_main_btn1a&question2==R.id.radio_main_btn2c||question1==R.id.radio_main_btn1b&question3==R.id.radio_main_btn3d||question1==R.id.radio_main_btn1a&question4==R.id.radio_main_btn4b||question2==R.id.radio_main_btn2c&question3==R.id.radio_main_btn3b||question2==R.id.radio_main_btn2c&question4==R.id.radio_main_btn4a||question3==R.id.radio_main_btn3b&question4==R.id.radio_main_btn4a) {
                    TxtMainEnd.setText("得分：50分");
                }else if (question1==R.id.radio_main_btn1a||question2==R.id.radio_main_btn2b||question3==R.id.radio_main_btn3b||question4==R.id.radio_main_btn4c) {
                    TxtMainEnd.setText("得分：25分");
                }else if (question1==-1||question2==-1||question3==-1||question4==-1) {
                    Toast.makeText(MainActivity.this, "请做出选择", Toast.LENGTH_SHORT).show();
                }else{
                    TxtMainEnd.setText("得分：0分");
                }
            }
        });
        btnMainCz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                radioMainBtn1a.setChecked(false);
                radioMainBtn1b.setChecked(false);
                radioMainBtn1c.setChecked(false);
                radioMainBtn1d.setChecked(false);
                radioMainBtn2a.setChecked(false);
                radioMainBtn2b.setChecked(false);
                radioMainBtn2c.setChecked(false);
                radioMainBtn2d.setChecked(false);
                radioMainBtn3a.setChecked(false);
                radioMainBtn3b.setChecked(false);
                radioMainBtn3c.setChecked(false);
                radioMainBtn3d.setChecked(false);
                radioMainBtn4a.setChecked(false);
                radioMainBtn4b.setChecked(false);
                radioMainBtn4c.setChecked(false);
                radioMainBtn4d.setChecked(false);
                TxtMainEnd.setText("");
                Toast.makeText(MainActivity.this,"重置完成",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        btnMainCz = (Button) findViewById(R.id.btn_main_cz);
        tvMainQ1 = (TextView) findViewById(R.id.tv_main_q1);
        gradMainQ1 = (RadioGroup) findViewById(R.id.grad_main_q1);
        radioMainBtn1a = (RadioButton) findViewById(R.id.radio_main_btn1a);
        radioMainBtn1b = (RadioButton) findViewById(R.id.radio_main_btn1b);
        radioMainBtn1c = (RadioButton) findViewById(R.id.radio_main_btn1c);
        radioMainBtn1d = (RadioButton) findViewById(R.id.radio_main_btn1d);
        tvMainQ2 = (TextView) findViewById(R.id.tv_main_q2);
        gradMainQ2 = (RadioGroup) findViewById(R.id.grad_main_q2);
        radioMainBtn2a = (RadioButton) findViewById(R.id.radio_main_btn2a);
        radioMainBtn2b = (RadioButton) findViewById(R.id.radio_main_btn2b);
        radioMainBtn2c = (RadioButton) findViewById(R.id.radio_main_btn2c);
        radioMainBtn2d = (RadioButton) findViewById(R.id.radio_main_btn2d);
        tvMainQ3 = (TextView) findViewById(R.id.tv_main_q3);
        gradMainQ3 = (RadioGroup) findViewById(R.id.grad_main_q3);
        radioMainBtn3a = (RadioButton) findViewById(R.id.radio_main_btn3a);
        radioMainBtn3b = (RadioButton) findViewById(R.id.radio_main_btn3b);
        radioMainBtn3c = (RadioButton) findViewById(R.id.radio_main_btn3c);
        radioMainBtn3d = (RadioButton) findViewById(R.id.radio_main_btn3d);
        tvMainQ4 = (TextView) findViewById(R.id.tv_main_q4);
        gradMainQ4 = (RadioGroup) findViewById(R.id.grad_main_q4);
        radioMainBtn4a = (RadioButton) findViewById(R.id.radio_main_btn4a);
        radioMainBtn4b = (RadioButton) findViewById(R.id.radio_main_btn4b);
        radioMainBtn4c = (RadioButton) findViewById(R.id.radio_main_btn4c);
        radioMainBtn4d = (RadioButton) findViewById(R.id.radio_main_btn4d);
        btnMainGet = (Button) findViewById(R.id.btn_main_get);
        TxtMainEnd = (EditText) findViewById(R.id.Txt_main_end);
    }
}